package com.atguigu.day18.lambda04.l2;

import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.function.Consumer;

/*

 */
public class ConsumerTest {
    ArrayList<String> list;
    @Before
    public void test00(){

        list = new ArrayList<>();
        Collections.addAll(list,"张三","李四","王五","赵六");
    }




    @Test
    public void test05(){
     /*  list.forEach(new Consumer<String>() {
           @Override
           public void accept(String s) {
               System.out.println("s = " + s);
           }
       });*/

        //list.forEach(s-> System.out.println(s));
        list.forEach(System.out::println);
    }


    @Test
    public void test01(){
        for(int i = 0;i<list.size();i++){
            System.out.println("普通for = " + list.get(i));
        }
    }
    @Test
    public void test02(){
        for (String s : list) {
            System.out.println("增强for  = " + s);
        }
    }
    @Test
    public void test03(){
        ListIterator<String> listedIterator = list.listIterator(list.size());

        while (listedIterator.hasPrevious()){
            String previous = listedIterator.previous();
            System.out.println("previous = " + previous);
        }
    }
    @Test
    public void test04(){
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println("next = " + next);
        }
    }
}
